<template>
  <div>
    <el-tabs type="border-card">
      <el-tab-pane label="新增单元">
        <el-form
          :model="ruleForm"
          :rules="rules"
          ref="ruleForm"
          label-width="100px"
          class="demo-ruleForm binglie"
          style="margin-top: 20px"
        >
          <el-form-item label="小区名称" prop="communityname">
            <el-input class="quku" v-model="ruleForm.communityname"></el-input>
          </el-form-item>

          <el-form-item label="单元名称" prop="unitname">
            <el-input class="quku" v-model="ruleForm.unitname"></el-input>
          </el-form-item>

          <el-form-item label="栋数" prop="unitnum">
            <el-input class="quku" v-model="ruleForm.unitnum" type="number"></el-input>
          </el-form-item>

          <el-form-item label="状态选择" prop="unitstatus">
            <el-select class="quku" v-model="ruleForm.unitstatus" placeholder="请选择状态">
              <el-option label="已建成" :value="1"></el-option>
              <el-option label="未建成" :value="2"></el-option>
            </el-select>
          </el-form-item>
        </el-form>

        <vue-ueditor-wrap
          v-model="ruleForm.unitcontext"
          :config="myConfig"
          style="margin: 20px 0 0 20px; width: 95%"
        />
      </el-tab-pane>
    </el-tabs>
    <div class="fanhuik">
      <el-button @click="fanhui" class="buttonn" type="primary"
        ><i class="el-icon-document-add"></i>返回</el-button
      >
      <el-button @click="baocun" class="buttonn" type="primary"
        ><i class="el-icon-top-left"></i>保存</el-button
      >
    </div>
  </div>
</template>

<script>
import VueUeditorWrap from "vue-ueditor-wrap";

export default {
  components: { VueUeditorWrap },
  data() {
    return {
      ruleForm: {
        communityname: "",
        unitname: "",
        unitnum: "",
        unitstatus: "",
        token: "",
        unitcontext: "",
        id: "",
      },

      rules: {
        communityname: [
          { required: true, message: "请输入小区名称", trigger: "blur" },
        ],
        unitname: [
          { required: true, message: "请输入单元名称", trigger: "blur" },
        ],
        unitnum: [{ required: true, message: "请输入栋数", trigger: "blur" }],
        unitstatus: [
          { required: true, message: "请选择状态", trigger: "change" },
        ],
      },
      myConfig: {
        UEDITOR_HOME_URL: "/UEditor/",
        initialFrameWidth: "100%",
        initialFrameHeight: 300,

        imageUrl: "/api/upload/image",
        imagePath: "/",
        imageAllowFiles: [".png", ".jpg", ".jpeg", ".gif", ".bmp"],

        fileUrl: "/api/upload/file",
        filePath: "/",
        fileAllowFiles: [".doc", ".docx", ".xls", ".xlsx", ".pdf", ".zip"],
        autoHeightEnabled: false,
      },
    };
  },
  created() {
    this.token = localStorage.getItem("token");
  },
  methods: {
    fanhui() {
      this.$router.push("/house/unit");
    },
    baocun() {
      this.gettian();
    },
    async gettian() {
      let res = await this.$axios.post(
        `http://community.byesame.com/house/addunitList`,
        {
          communityname: this.ruleForm.communityname,
          token: this.ruleForm.token,
          unitcontext: this.ruleForm.unitcontext,
          unitname: this.ruleForm.unitname,
          unitnum: this.ruleForm.unitnum,
          unitstatus: this.ruleForm.unitstatus,
        }
      );
      console.log("添加成功", res);
      this.$message({
        message: "添加成功",
        type: "success",
      });
      this.$router.push("/house/unit");
    },
  },
};
</script>

<style scoped>
.demo-ruleForm {
  padding-right: 20px;
}
.fanhuik {
  position: absolute;
  right: 1.25rem;
  z-index: 999;
  top: 8rem;
}
.fanhuik .buttonn {
  display: block;
  margin-top: 1.25rem;
  margin-left: 0;
}
.binglie {
  width: 93%;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}
.quku{
  width: 31.25rem;
}
</style>